package com.mi.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mi.entity.AuthInfo;
import com.mi.mapper.AuthMapper;
import com.mi.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AuthController {

    @Autowired
    AuthService authService;

    @Autowired
    AuthMapper authMapper;

    //获取所有的权限信息
    @RequestMapping("queryAuth")
    @ResponseBody
    public List<AuthInfo> queryAuth(HttpServletRequest request){
        List<AuthInfo> authPojos = authService.queryAuth(new AuthInfo());
        return authPojos;
    }

    //转发到权限管理界面
    @RequestMapping("authList")
    public String adminAuth(AuthInfo authInfo,HttpServletRequest request){
        PageHelper.startPage(authInfo.getPageNum(),authInfo.getPageSize());
        authInfo.setAutype(String.valueOf(2));
        List<AuthInfo> authPojos = authMapper.queryAuthsss(authInfo);
        PageInfo<AuthInfo> list = new PageInfo<>(authPojos);
        request.setAttribute("pageInfo",list);
        request.setAttribute("aupath",authInfo.getAupath());
        request.setAttribute("auname",authInfo.getAuname());
        return "authList";
    }
}
